﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PB.Airsoft.Business.User;
using PB.Airsoft.Web.Business;
using PB.Airsoft.Business.Item;
using PB.Airsoft.Business.Shop;

namespace PB.Airsoft.Web.city.controls
{
    public partial class SellItemControl : System.Web.UI.UserControl
    {
        protected void Page_PreRender(object sender, EventArgs e)
        {
            ddlUserInventoryItems.DataSource = UserManager.GetUserInventoryItems(AppContext.Current.User.Id).Select(userInventoryItem => ItemManager.GetItem(userInventoryItem.ItemId));
            ddlUserInventoryItems.DataBind();
        }

        protected void btnSell_Click(object sender, EventArgs e)
        {
            Guid itemId = new Guid(ddlUserInventoryItems.SelectedValue);
            var itemToSell = ItemManager.GetItem(itemId);
            if (itemToSell == null)
                return;

#warning money filter
            decimal money = decimal.Parse(txtPrice.Text);

            ShopManager.Sell(itemToSell, money, AppContext.Current.User.Id);
        }
    }
}